package com.android.sharecar.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.Spinner;

/**
 * 搭车界面
 * @author xinyan
 *@date 2011-9-13
 */
public class PickRideActivity extends Activity {

	// members
	private EditText mStartPlace, mEndPlace;
	private ImageButton mStartPlaceFavorite, mEndPlaceFavorite;
	private Spinner mPickRideNum;
	private Button mSubmit;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.pickride);

		findViews();

		setListenerForViews();
	}

	private void findViews() {
		mEndPlace = (EditText) findViewById(R.id.pickrideactivity_et_endPlace);
		mStartPlace = (EditText) findViewById(R.id.pickrideactivity_et_startPlace);
		mPickRideNum = (Spinner) findViewById(R.id.pickrideactivity_sp_pickRideNum);
		mStartPlaceFavorite = (ImageButton) findViewById(R.id.pickrideactivity_ib_startPlace_favorite);
		mEndPlaceFavorite = (ImageButton) findViewById(R.id.pickrideactivity_ib_endPlace_favorite);
		mSubmit = (Button) findViewById(R.id.pickrideactivity_btn_submit);

		ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(
				this, R.array.select_dialog_vacantSeatNum,
				android.R.layout.simple_spinner_item);
		adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
		mPickRideNum.setAdapter(adapter);
	}

	private void setListenerForViews() {
		mStartPlaceFavorite.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				startActivity(new Intent(PickRideActivity.this,
						AddressFavoriteActivity.class));
			}
		});

		mEndPlaceFavorite.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				startActivity(new Intent(PickRideActivity.this,
						AddressFavoriteActivity.class));
			}
		});

		mSubmit.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				Intent intent = new Intent();
				intent.setClass(PickRideActivity.this,
						MainTabWidgetActivity.class);
				intent.putExtra("state", 1);
				startActivity(intent);
			}
		});
	}
}
